﻿Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports DotNetNuke.Entities.Modules
Imports Aricie.DNN.Modules.LuceneSearch.Settings
Imports DotNetNuke.Services.Search

Namespace Aricie.DNN.Modules.LuceneSearch.ModuleProviders
    Public Class CompoundISearchable
        Implements ISearchable

        Private _NativeSearchable As ISearchable
        Private _ModuleProvider As LuceneModuleProviderConfig

        Public Sub New(ByVal nativeSearchable As ISearchable, ByVal moduleProvider As LuceneModuleProviderConfig)
            Me._NativeSearchable = nativeSearchable
            Me._ModuleProvider = moduleProvider
        End Sub


        Public Function GetSearchItems(ByVal modInfo As DotNetNuke.Entities.Modules.ModuleInfo) As DotNetNuke.Services.Search.SearchItemInfoCollection Implements DotNetNuke.Entities.Modules.ISearchable.GetSearchItems
            Dim toReturn As New SearchItemInfoCollection
            If Not _ModuleProvider.DiscardNativeProvider Then
                toReturn.AddRange(Me._NativeSearchable.GetSearchItems(modInfo))
            End If
            Dim addItems As SearchItemInfoCollection = Me._ModuleProvider.AsSearchable.GetSearchItems(modInfo)
            For Each item As SearchItemInfo In addItems
                Dim toAdd As LuceneSearchItemInfo = LuceneSearchItemInfo.GetLuceneSearchItem(item, modInfo.PortalID, _ModuleProvider.Name)
                toReturn.Add(toAdd)
            Next
            Return toReturn
        End Function
    End Class
End Namespace